package org.example.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.example.dao.ad.AdMapper;
import org.example.entity.Ad;
import org.example.entity.PageBean;
import org.example.service.AdService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdServiceImpl implements AdService {

    @Resource
    private AdMapper adMapper;

    /**
     * 按照条件分页查询广告
     * **/
    @Override
    public PageBean<Ad> adByReason(Integer pageSize, Integer page, Integer advId,
                                   String goodsName, String title, String status) {
        if (status.equals("是")) {
            status = "1";
        }else if (status.equals("否"))
            status = "0";
        PageHelper.startPage(page,pageSize);
        List<Ad> list = adMapper.listByReason(advId,goodsName,title,status);

        Page<Ad> p = (Page<Ad>) list;

        long total = p.getTotal();
        list = p.getResult();

        return new PageBean<Ad>(total,list);
    }

    /**
     * 插入广告
     * **/
    @Override
    public void insertAd(Ad ad) {
        adMapper.insertAd(ad);
    }

    /**
     *删除广告
     * **/
    @Override
    public void deleteAd(Integer advId) {
        adMapper.DeleteAd(advId);
    }

    /**
     *更新广告
     * **/
    @Override
    public void updateAd(Ad ad) {
        adMapper.updateAd(ad);
    }

    /**
     * 获取ad列表
     * */    @Override
    public List<Ad> getAdList() {
        return adMapper.list();
    }
}
